package com.cfwx.thread;

public class TestStatic {
	static Integer count = 0; 
    public static void main(String[] args) { 
        Print t1 = new Print(); 
        Print t2 = new Print(); 
        Print t3 = new Print(); 
         
        new Thread(t1,"t1").start(); 
        new Thread(t2,"t2").start(); 
        new Thread(t3,"t3").start(); 
        
        try {
			Thread.sleep(1);//运行1毫秒后结束线程
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		
		t1.shutdown();
		t2.shutdown();
		t3.shutdown();
        
    } 
}

class Print implements Runnable { 
    public boolean stopFlag = false;
    public void run () { 
    	
        while (!stopFlag) 
        { 
            synchronized (TestStatic.count) { 
                TestStatic.count++; 
                if (TestStatic.count == 1) { 
                    System.out.println (Thread.currentThread().getName()+" A"); 
                } else if (TestStatic.count == 2) { 
                    System.out.println (Thread.currentThread().getName()+" B"); 
                } else if (TestStatic.count == 3) { 
                    System.out.println (Thread.currentThread().getName()+" C"); 
                } else { 
                	TestStatic.count=0;
                }             
            } 
        } 
    }
    
    public void shutdown(){
    	this.stopFlag=true;
    }
    
    
}
